Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Compute the determinant of an array in Python using the NumPy linear algebra package
ResourceFunction["NumPyDet"][array] computes the determinant of array in Python using the package NumPy. | |
ResourceFunction["NumPyDet"][array,session] uses the specified running ExternalSessionObject session. |
Compute the determinant of a matrix in NumPy:
In[1]:= |
|
In[2]:= |
|
Out[2]= |
|
Or using the built-in Wolfram Language function:
In[3]:= |
|
Out[3]= |
|
Compute the determinant of a real-valued matrix:
In[4]:= |
|
Out[4]= |
|
In[5]:= |
|
Out[5]= |
|
Sparse array:
In[6]:= |
|
Out[6]= |
|
NumericArray object:
In[7]:= |
|
Out[7]= |
|
Complex-valued array:
In[8]:= |
|
Out[8]= |
|
A tensor representing a list of matrices:
In[9]:= |
|
Out[9]= |
|
In[10]:= |
|
Out[10]= |
|
In[11]:= |
|
Out[11]= |
|
Compare with the built-in Det:
In[12]:= |
|
Out[12]= |
|
Make several calls to NumPyDet in the same external session:
In[13]:= |
|
Out[13]= |
|
In[14]:= |
|
Out[14]= |
|
In[15]:= |
|
Out[15]= |
|
End the session:
In[16]:= |
|
For relatively large matrices, the determinant cannot be computed using machine arithmetic:
In[17]:= |
|
In[18]:= |
|
Out[18]= |
|
Use the resource function NumPySignLogDet instead:
In[19]:= |
|
Out[20]= |
|
In[21]:= |
|
Out[21]= |
|
Or the built-in Det:
In[22]:= |
|
Out[22]= |
|
Automatic conversion of the input array to a NumericArray object can fail:
In[23]:= |
|
Out[23]= |
|
In[24]:= |
|
Out[24]= |
|
Convert the array to a NumericArray before passing it to NumPyDet:
In[25]:= |
|
Out[25]= |
|
A call to NumPyDet on an arbitrary precision array fails:
In[26]:= |
|
Out[26]= |
|
In[27]:= |
|
Out[27]= |
|
Convert the array to a NumericArray before passing it to NumPyDet:
In[28]:= |
|
Out[28]= |
|
Or use the machine-precision array:
In[29]:= |
|
Out[29]= |
|
NumPyDet does not issue a warning when precision is lost:
In[30]:= |
|
In[31]:= |
|
Out[31]= |
|
Compare with the built-in Det computed with machine precision:
In[32]:= |
|
Out[32]= |
|
Obtain a more accurate result by computing the determinant with a higher precision using the built-in Det:
In[33]:= |
|
Out[33]= |
|
Verify the result by using still higher precision:
In[34]:= |
|
Out[34]= |
|
This work is licensed under a Creative Commons Attribution 4.0 International License